namespace CRMG.Container.Source.DL
{
    using CRMG.Container.Source.BO;
    using CRMG.Container.Source.Helper;
    using Guru.Framework.BaseDal;
    using Guru.Framework.QueryBuilding;
    using System;
    using System.Data;

    public class TrainDL : BaseDL
    {

        public TrainDL()
        {
        }

        public DataTable GetTrains()
        {
            try
            {
                QueryBuilder qB = base.Manager.CreateQueryBuilder(QueryTypes.Select, new Train());
                return base.Manager.GetResultSet(qB.QueryString).Tables[0];
            }
            catch (Exception)
            {
                throw;
            }
        }

        public Train GetTrainById(int trainId)
        {
            try
            {
                Train train = new Train() { OBJID = trainId };
                DataTable dt = GetById(train);
                train = null;
                foreach (DataRow row in dt.Rows)
                {
                    train = new Train()
                    {
                        OBJID = row["OBJID"].ToInt(),
                        TrainName = row["TrainName"].ToStr(),
                        Definiton = row["Definiton"].ToStr(),
                        Vendor = row["Vendor"].ToInt(),
                    };
                }
                return train;
            }
            catch (Exception)
            {
                throw;
            }
        }

        public Train GetTrainByVendorAndName(string name, int vendorId)
        {
            try
            {
                Train train = new Train() { TrainName = name, Vendor = vendorId };
                DataTable dt = GetWhereChangeColumnList(train);
                train = null;
                foreach (DataRow row in dt.Rows)
                {
                    train = new Train()
                    {
                        OBJID = row["OBJID"].ToInt(),
                        TrainName = row["TrainName"].ToStr(),
                        Definiton = row["Definiton"].ToStr(),
                        Vendor = row["Vendor"].ToInt(),
                    };
                }
                return train;
            }
            catch (Exception)
            {
                throw;
            }
        }

    }
}

